package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * wangcong
 * 2025/2/10 17:33
 */
@RequestMapping("/iot")
@Api(tags = "设备管理")
@RestController
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct() {
        List<ProductVo> list = deviceService.allProduct();
        return ResponseResult.success(list);
    }


    @PostMapping("/RegisterDevice")
    public ResponseResult RegisterDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }

    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto) {
         PageResponse<DeviceVo> pageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
         return ResponseResult.success(pageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> QueryDeviceDetail(@RequestBody DeviceDto deviceDto) {
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult QueryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) {
        HashMap<String, QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyDataList> map = deviceService.queryDevicePropertyStatus(deviceDto);
        return ResponseResult.success(map);
    }

    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<Map<String,String>> QueryThingModelPublished(@RequestBody DeviceDto deviceDto) {
        Map<String,String> res = deviceService.queryThingModelPublished(deviceDto);
        return ResponseResult.success(res);
    }

    @PostMapping("/UpdateDevice")
    public ResponseResult UpdateDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/DeleteDevice")
    public ResponseResult DeleteDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.deleteDevice(deviceDto);
        return ResponseResult.success();
    }
}
